﻿using System;
using System.Web.UI.WebControls;
using Ue.Framework.Web;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.SinglePages;
namespace Ue.Qcdz.UI.Controls
{
    public class SinglePageShow : SkinnedControl
    {
        private SinglePageType.SgPage _PageType;
        private Literal ltrTitle;
        private Literal ltrContent;
        public string Title { get; set; }

        public SinglePageType.SgPage PageType
        {
            get { return _PageType; }
            set { _PageType = value; }
        }

        protected override string GetSkinFileName()
        {
            return string.Empty;
        }

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            ltrTitle = skin.FindControl<Literal>("ltrTitle");
            ltrContent = skin.FindControl<Literal>("ltrContent");
            BinToControl();
        }

        public void BinToControl()
        {
            string keyId = Page.Request.GetQueryValue<string>("ID");

            Guid key = new Guid();
            if (!string.IsNullOrEmpty(keyId))
                key = new Guid(keyId);
            else
                key = new Guid(SinglePageType.GetSinglePageKey(PageType));



            SinglePage model = SinglePageService.GetSinglePage(key);
            if (model == null) return;
            if (this.ltrTitle != null)
                ltrTitle.Text = this.Page.Title = model.Title;
            Title = model.Title;
            if (ltrContent != null)
                ltrContent.Text = model.Content;
        }

    }
}
